<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<link rel="stylesheet" type="text/css" href="${ctxPath}/static/magic-input/magic-input.min.css">
<style>
</style>
<script type="text/javascript">
    var socket;
    //实际生产中，id可以从session里面拿用户id
    // var id  = Math.random().toString(36).substr(2);
    var id="${sessionId}";
    if(!window.WebSocket){
        window.WebSocket = window.MozWebSocket;
    }

    if(window.WebSocket){
        socket = new WebSocket("ws://localhost:7397");

        socket.onmessage = function(event){
            var data=JSON.parse(event.data);
            console.log(data.type)
            console.log(data.msg);
            appendln("receive:" + event.data);
        };

        socket.onopen = function(event){
            appendln("WebSocket is opened");
            login();
        };

        socket.onclose = function(event){
            appendln("WebSocket is closed");
        };
    }else{
        alert("WebSocket is not support");
    }


    function appendln(text) {
        var ta = document.getElementById('responseText');
        ta.value += text + "\r\n";
    }

    function login(){
        console.log("aaaaaa");
        var date={"id":id,"type":"aa"};
        var login = JSON.stringify(date);
        socket.send(login);
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false" >
    <div data-options="region:'center',border:false" style="overflow-x:hidden;overflow-y: auto;padding: 3px;" >
        <form onSubmit="return false;">
            <input type = "text" name="message" value="hello"/>
            <br/><br/>

            <textarea id="responseText" style="width: 800px;height: 300px;"></textarea>
            <input type="submit">
        </form>
    </div>
</div>